Skip to content

Preserve UTC offsets when normalizing time-only strings - #1095

Open
Twiink wants to merge 1 commit into
python-pendulum:masterfrom
Twiink:fix/time-only-offset-20261119
Open

Twiink wants to merge 1 commit into
python-pendulum:masterfrom
Twiink:fix/time-only-offset-20261119

Conversation

@Twiink

@Twiink Twiink commented Nov 19, 2026

Copy link
Copy Markdown

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Preserve the offset of time-only strings

pendulum.parse("20:12:05+05:30") loses the explicit offset when the parsed time is normalized to today's datetime. The result is interpreted as UTC (or the fallback tz option), changing the instant by several hours. Full datetime strings already retain their explicit offsets.

Pass the parsed time's tzinfo into the normalized datetime. Twelve regression cases exercise the low-level and public parsers with positive, negative, zero, and Z offsets, including an explicit fallback timezone. On the unchanged implementation, 10 cases fail and 2 controls pass.

Validation on Linux / Python 3.13:

  • Complete pure-Python suite: 1,883 passed, 3 existing skips.
  • Complete native-extension suite: 1,883 passed, 3 existing skips; confirmed imports use the built Rust parser.
  • Mypy: passed, 228 files.
  • Ruff lint and format checks: passed.
  • git diff --check: passed.

The parsing documentation now includes a time-only offset example. Prepared and validated with AI assistance (OpenAI Codex).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant